import RegionData from '@/assets/data/area.json';
import { deepClone } from './base';

const codeMap = regionData => {
  const loop = (col, item) => {
    const { value, label, children } = item;
    col[value] = label;
    Array.isArray(children) ? children.reduce(loop, col) : null;
    return col;
  };
  return regionData.reduce(loop, {});
};

export const regionData = deepClone(RegionData);

export const codeToText = codeMap(regionData);
